#include<iostream>
#include "leftist_heap.h"
#include<map>
#include<vector>
#include<time.h>
#include<random>
#include<algorithm>
#include<fstream>

int main(int args, char* argv[])
{
    int number = atoi(argv[1]);
    vector<Data<int, int>> vec;
    
    LeftistHeap<int, int> A;
    LeftistHeap<int, int> B;    
    
    std::cout << "-===========leftist heap=============-" << std::endl;

    time_t start;
    time_t end;
/*********************************生成图像和算法分析测试***************************/
    //ofstream result;

	// result.open("result", ios::out);
	// result << "Size " << "Build_time " << "Remove_time" << endl;
    // for(int k=0; k<100000; k+=10){
    //     for(int i=0; i<=k; ++i)
    //     {
    //         vec.push_back(Data<int, int>(i, i+1));
    //     }
    //     // cout << "Build_Heap test: " << endl;
    //     start = clock();
    //     A.buildHeap(vec);
    //     end = clock();
    //     double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    //     // cout << "Time consuming: "<< endtime << endl;
    //     result << k << " " << endtime << " ";

    //     cout << endl;
    //     // cout << "Remove test" << endl;

    //     std::shuffle(vec.begin (), vec.end (), std::default_random_engine (time(0)));
    //     start = clock();
    //     for(auto& i:vec)
    //     {
    //         A.remove(i.k);
    //     }
    //     end = clock();
    //     endtime=(double)(end-start)/CLOCKS_PER_SEC;
    //     // cout << "Removing Time consuming: "<< endtime << endl;
    //     result << endtime << endl;
    //     vec.clear();
    //     A.makeEmpty();
    // }

/******************************简单测试***************************/
    cout << endl;
    for(int i=0; i<=number; ++i)
    {
        vec.push_back(Data<int, int>(i, i+1));
    }
    cout << "Build_Heap test: " << endl;
    start = clock();
    A.buildHeap(vec);
    end = clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    cout << "Time consuming: "<< endtime << endl;
    A.describe();

    cout << endl;
    cout << "Remove test" << endl;

    std::shuffle(vec.begin (), vec.end (), std::default_random_engine (time(0)));
    start = clock();
    for(auto& i:vec)
    {
        A.remove(i.k);
    }
    end = clock();
    endtime=(double)(end-start)/CLOCKS_PER_SEC;
    cout << "Removing Time consuming: "<< endtime << endl;
    A.describe();

    cout << endl;
    cout << "Insertion test" << endl;
    A.insert(Data<int,int>(-1,-1));
    A.insert(Data<int, int>(-2, -2));
    A.insert(Data<int, int>(3, 2));
    A.describe();

    cout << endl;
    cout << "Modify test add 10 to the value with the key -1" << endl;
    A.modifyData(-1, 10);
    A.describe();

    cout << endl;
    cout << "DeleteMin test" << endl;
    A.deleteMin();
    A.describe();
    
    return 0;

}

